package cn.kgc.controller;

import cn.kgc.entity.Order;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

/**
 * @Author: 课工场
 * @Version: v1.0  2023/4/20
 * @Description:
 */
@RequestMapping("order")
@RestController
public class OrderController {

    @RequestMapping("m1")
    public String method1(){
        return " order ok";
    }

    @RequestMapping("m2")
    public String method2(){
        return " order ok";
    }

    @RequestMapping("m3")  // 根据用户名查询订单  ?
    public List<Order> method3(String  username){

        Order order = new Order();
        order.setId(1);
        order.setUsername(username);
        order.setProductName("手机");
        List<Order> orders = Arrays.asList(order, order, order);

        return orders;
    }

    @RequestMapping("m4/{id}")  // 根据id查询订单
    public Order method4(@PathVariable("id") Integer id){

        Order order = new Order();
        order.setUsername("jack");
        order.setId(id);
        order.setProductName("手机");

        return order;
    }


    @RequestMapping("m5")  // 保存订单
    public String method5(Order order){
        System.out.println("order = " + order);
        return "ok";
    }

    @RequestMapping("m6")  // 修改订单  json
    public String method6(@RequestBody Order order){
        System.out.println("order = " + order);
        return "ok";
    }




}